﻿// See https://aka.ms/new-console-template for more information
namespace MoveTest
{
    class Program
    {
        /// <summary>
        /// MoveTest
        /// </summary>
        const int CountOfTest = 10;
        static void Main()
        {
            int CountOfError = 0;
            //产生随机数
            Random rnd = new ();
            double Time = 0;
            //统计循环开始的时间
            DateTime StartTime = DateTime.Now;
            string[] array = { "上", "下", "左", "右" };
            for (int i = 0; i < CountOfTest; i++)
            {
                //开始测试
                Console.Clear();
                Console.WriteLine($"现在进行的是第{i + 1}次测试,总耗时{Time}秒，共错{CountOfError}次");
                Console.WriteLine("请根据指令按键盘的方向键");
                //得到随机方向，并输出显示
                String direaction = array[rnd.Next(0, 4)];
                Console.WriteLine(direaction);
                bool flag = false;
                //循环
                do
                {
                    //读入键盘指令，判断是否键盘输入一致
                    var key = Console.ReadKey();
                    switch (direaction)
                    {
                        case "上":
                            if (key.Key == ConsoleKey.UpArrow) flag = true;
                            break;
                        case "下":
                            if (key.Key == ConsoleKey.DownArrow) flag = true;
                            break;
                        case "左":
                            if (key.Key == ConsoleKey.LeftArrow) flag = true;
                            break;
                        case "右":
                            if (key.Key == ConsoleKey.RightArrow) flag = true;
                            break;
                        default:
                            break;
                    }
                    //每次输错后错误次数+1
                    if (flag == false) CountOfError++;
                } while (flag == false);
                //统计循环结束的时间
                DateTime EndTime = DateTime.Now;
                //计算总耗时
                Time = (EndTime - StartTime).TotalSeconds;
            }
        }
    }
}